package com.ruoyi.merchant.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.merchant.api.RemoteMerchantService;
import com.ruoyi.merchant.api.domain.Merchant;
import com.ruoyi.merchant.api.domain.ServiceManagement;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteMerchantFallbackFactory implements FallbackFactory<RemoteMerchantService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteMerchantFallbackFactory.class);

    @Override
    public RemoteMerchantService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteMerchantService()
        {
            @Override
            public R<TableDataInfo> list(Merchant merchant) {
                return R.fail("获取商户列表失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult getInfo(Long mId) {
                return AjaxResult.error("获取商户信息失败:" + throwable.getMessage());
            }

            @Override
            public R<TableDataInfo> selectPassedAndNotDelMerchantList(Merchant merchant) {
                return R.fail("获取已审核且未被删除的商户列表失败:" + throwable.getMessage());
            }

            @Override
            public R<TableDataInfo> selectOpeningMerchantList(Merchant merchant) {
                return R.fail("获取正在营业的商户列表失败:" + throwable.getMessage());
            }
            @Override
            public R<TableDataInfo> PassedMerchantsList(String source) {
                return R.fail("获取已通过审核的商户列表失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult selectServiceManagementBySmId(Long smId) {
                return AjaxResult.error("获取服务管理信息失败:" + throwable.getMessage());
            }
        };
    }
}
